//package com.example.android_demo2.room
//
//import android.os.Bundle
//import androidx.appcompat.app.AppCompatActivity
//import androidx.recyclerview.widget.LinearLayoutManager
//import androidx.room.Room
//import com.chad.library.adapter.base.BaseQuickAdapter
//import com.chad.library.adapter.base.viewholder.BaseViewHolder
//import com.example.android_demo2.R
//import com.example.android_demo2.databinding.ActivityRoomBasicBinding
//
//class RoomActivity : AppCompatActivity() {
//
//    var binding: ActivityRoomBasicBinding? = null
//    private var adapter: RyListAdapter? = null
//    private var wordDataBase: WordDatabase? = null
//    private var wordDao: WordDao? = null
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        binding = ActivityRoomBasicBinding.inflate(layoutInflater)
//        setContentView(binding?.root)
//
//        wordDataBase = Room
//            .databaseBuilder(this, WordDatabase::class.java, "word_database")
//            .allowMainThreadQueries()
//            .build()
//        wordDao = wordDataBase?.getWordDao()
//
//        initRecyclerView()
//        initClick()
//    }
//
//    private fun initRecyclerView() {
//        binding?.recyclerView?.layoutManager = LinearLayoutManager(this)
//        adapter = RyListAdapter()
//        binding?.recyclerView?.adapter = adapter
//    }
//
//    private fun initClick() {
//        binding?.btnInsert?.setOnClickListener {
//            val word1 = Word(1, "Hello", "你好")
//            val word2 = Word(2, "World", "世界")
//            wordDao?.insertData(word1, word2)
//            updateView()
//        }
//
//        binding?.btnUpdate?.setOnClickListener {
//
//        }
//
//        binding?.btnClear?.setOnClickListener {
//
//        }
//
//        binding?.btnDelete?.setOnClickListener {
//
//        }
//    }
//
//    fun updateView() {
//        var list = wordDao?.getAllWords()?.toMutableList()
//        adapter?.setNewInstance(list)
//    }
//
//
//    class RyListAdapter : BaseQuickAdapter<Word, BaseViewHolder>(R.layout.room_item) {
//        override fun convert(holder: BaseViewHolder, item: Word) {
//            holder.setText(R.id.tv_text, item.world)
//        }
//    }
//}